package demo.web.ui.ctrl;

import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.validator.AbstractValidator;

public class UserValidator extends AbstractValidator {

	public void validate(ValidationContext ctx) {
		String firstName = (String)ctx.getProperties("firstName")[0].getValue();
		String lastName = (String)ctx.getProperties("lastName")[0].getValue();
		String login = (String)ctx.getProperties("login")[0].getValue();
		String password = (String)ctx.getProperties("password")[0].getValue();

		if(firstName == null || "".equals(firstName))
			this.addInvalidMessage(ctx, "firstName", "You must enter a first name");		

		if(lastName == null || "".equals(lastName))
			this.addInvalidMessage(ctx, "lastName", "You must enter a last name");

		if(login == null || "".equals(login))
			this.addInvalidMessage(ctx, "login", "You must enter a login");

		if(password == null || "".equals(password))
			this.addInvalidMessage(ctx, "password", "Passwords must be the same");
	}
}
